package com.qf.cloud2204.feign.controller;

import com.qf.cloud2204.common.entity.User;
import com.qf.cloud2204.feign.feignclient.MicroAClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/f")
public class FeignController {

    @Autowired
    MicroAClient microAClient;


    @GetMapping("/test1")
    public String test1(){

        // 调用微服务A 的 hello接口
        String result = microAClient.hello();  // 好像一个本地方法调用
        System.out.println(result);
        return result;
    }

    @GetMapping("/test2")
    public String test2(){
        // 调用微服务A的 findAll 接口
        List<User> users = microAClient.findAll();
        System.out.println(users);
        return users.toString();
    }

    @GetMapping("/test3")
    public User test3(){
        // 调用微服务A的 update接口
        User luobin = new User(300, "luobin");
        User user = microAClient.updateUser(luobin);
        return user;
    }

    @GetMapping("/test4")
    public User test4(){
        // 调用微服务A的 delete 接口
        User user = microAClient.deleteUser(100);
        return user;
    }

    @GetMapping("/test5")
    public User test5(){
        // 调用微服务A的 delete 接口
        User user = microAClient.findUserByName("zhangsan");
        return user;
    }

}
